export const formartLang = (locale) => {
  switch (locale) {
    case 'zhHans':
      return 'cn';
    case 'zhHant':
      return 'cn';
    case 'ja':
      return 'jp';
    case 'en':
      return 'en';
    default:
      return 'en';
  }
};

export const getTokyoDaysOfCurrentMonth = (date) => {
  const options = {
    timeZone: 'Asia/Tokyo',
    year: 'numeric',
    month: 'numeric'
  };
  // 东京9小时偏移量
  const now = date ? new Date(date + 'T00:00:00+09:00') : new Date();
  const tokyoDate = new Intl.DateTimeFormat('ja-JP', options).format(now);

  const [year, month] = tokyoDate.split('/').map(Number);
  const daysInMonth = new Date(year, month, 0).getDate(); // 获取当月天数
  const tokyoDays = [];

  for (let day = 1; day <= daysInMonth; day++) {
    tokyoDays.push(`${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`);
  }
  return tokyoDays;
};

export const formatDate = (date) => {
  const year = String(date.getFullYear());
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  return year + '-' + month + '-' + day;
};

export const formatTime = (date) => {
  const hours = String(date.getHours()).padStart(2, '0'); // 获取小时并补零
  const minutes = String(date.getMinutes()).padStart(2, '0'); // 获取分钟并补零
  return `${hours}:${minutes}`;
};

// 计算间隔天数
export const calculateDays = (startStr, endStr) => {
  // 将日期字符串转换为Date对象（处理为本地时间）
  const parseDate = (str) => new Date(str.replace(' ', 'T') + ':00');

  const start = parseDate(startStr);
  const end = parseDate(endStr);

  // 计算时间差（毫秒）
  const diff = Math.abs(end - start);

  // 计算24小时为单位的间隔天数（向上取整）
  return Math.ceil(diff / (24 * 60 * 60 * 1000));
};
